package com.kehutong.payment.util;

import org.coraframework.json.JSONObject;

public enum TencentPayResult {

	/** 成功*/
	SUCCESS("SUCCESS"),
	/** 失败*/
	FAIL("FAIL");
	
	public final String code;
	
	private TencentPayResult(String code) {
		this.code = code;
	}
	
	@Override
	public String toString() {
		return code;
	}
	
	public boolean equipsAll(String...results) {
		for (String str : results) {
			if (code.equals(str)) {
				return true;
			}
		}
		
		return false;
	}
	
	
	public static boolean isOk(JSONObject result, String...names) {
		for (String name : names) {
			if (SUCCESS.code.equals(result.getString(name))) {
				return true;
			}
		}
		
		return false;
	}

	/**
	 * 传的所有参数必须为SUCCESS
	 * @param result
	 * @param names
	 * @return
	 */
	public static boolean isSuccess(JSONObject result, String...names) {
		for (String name : names) {
			if (!SUCCESS.code.equals(result.getString(name))) {
				return false;
			}
		}

		return true;
	}

	/**
	 * 如果有一个状态是FAIL，即返回true
	 * @param result
	 * @param names
	 * @return
	 */
	public static boolean isFail(JSONObject result, String...names) {
		for (String name : names) {
			if (FAIL.code.equals(result.getString(name))) {
				return true;
			}
		}

		return false;
	} 
}
